package com.ygqh.baby.service.impl;
import java.util.List;
import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.YgImages;
import  com.ygqh.baby.mapper.YgImagesMapper;
import  com.ygqh.baby.service.YgImagesService;
import  org.springframework.util.Assert;
import java.util.Arrays;
import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.YgImagesExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class YgImagesServiceImpl implements YgImagesService{
	
	@Autowired
	private YgImagesMapper ygImagesMapper;
	
	@Override
	public List<YgImages> find() {
		YgImagesExample example = new YgImagesExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygImagesMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgImagesExample example = new YgImagesExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygImagesMapper.countByExample(example);
	}

	@Override
	public YgImages findById(Long id) {
		return ygImagesMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(YgImages ygImages) {
		return ygImagesMapper.insertSelective(ygImages);
	}

	@Override
	public int update(YgImages ygImages) {
		return ygImagesMapper.updateByPrimaryKeySelective(ygImages);
	}

	@Override
	public ResultSet<YgImages> search(QueryInfo queryInfo,String q) {
		List<YgImages>  list =  ygImagesMapper.selectSuper(queryInfo, q);
		int count = ygImagesMapper.countSuper(q);
		ResultSet<YgImages> resultSet = new ResultSet<YgImages>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		YgImagesExample example = new YgImagesExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		YgImages record = new YgImages();
		record.setStatus(DataStatus.Delete);

		return ygImagesMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(YgImages ygImages) {
		int r = 0;
		if(ygImages.getId() != null) {
			r = this.update(ygImages);
		}else {
			r = this.save(ygImages);
		}
		return r;
	}

}

